<?php
/**
 * 我的代金券
 *
 
 
 
 

 */

defined('IN_NWIDC') or exit('Access Invalid!');

class member_voucherControl extends mobileMemberControl {

	public function __construct() {
		parent::__construct();
	}

    /**
     * 地址列表
     */
    public function voucher_listOp() {
		$model_voucher = Model('voucher');
        $voucher_list = $model_voucher->getMemberVoucherList($this->member_info['member_id'], $_POST['voucher_state'], $this->page);
        $page_count = $model_voucher->gettotalpage();

        output_data(array('voucher_list' => $voucher_list), mobile_page($page_count));
    }

    public function voucher_exchangeOp(){
        $model_voucher = Model('voucher');
        $where = array();
        $where['voucher_t_state'] = 1;
        $where['voucher_t_end_date'] = array('gt',time());
        $voucherlist_ = $model_voucher->getVoucherTemplateList($where, '*', 0, 18);
        foreach( $voucherlist_  as $k => $v){
            if($v['voucher_t_total'] > $v['voucher_t_giveout']){
                $voucherlist [$k] = $v;
            }
        }
        output_data(array('voucher_list' => $voucherlist));
    }

    /**
     * 兑换代金券保存信息
     *
     */
    public function voucherexchange_saveOp(){

        $vid = intval($_POST['vid']);
        if ($vid <= 0){
            echo false;
        }
        $model_voucher = Model('voucher');
        //验证是否可以兑换代金券
        $data = $model_voucher->getCanChangeTemplateInfo($vid,intval($this->member_info['member_id']),intval($this->member_info['store_id']));
        if ($data['state'] == false){
            echo false;
        }
        //添加代金券信息
        $data = $model_voucher->exchangeVoucher($data['info'],$this->member_info['member_id'],$this->member_info['member_name']);
        if ($data['state'] == true){
            echo true;
        } else {
            echo false;
        }
    }
}
